package interview;

import java.util.*;

/**
 * User: Asuka
 * Date: 10-12-26
 * Time: 下午1:33
 */
public class FILO {
    private static final int TEST_TIME = 1000;

    public static void main(String[] args) {
        Deque<Character> stack = new ArrayDeque<Character>();
        Set<String> result = new TreeSet<String>();
        for (int i = 0; i < TEST_TIME; i++) {
            test(stack, "ABCDEF", result);
        }
        System.out.println(result);
        System.out.println("共:" + result.size());
    }

    public static void test(Deque<Character> stack, String input, Set<String> result) {
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            stack.push(input.charAt(i));
            if (Math.random() > 0.5) {
                if (stack.isEmpty()) return;
                out.append(stack.pop());
            }
        }
        while (!stack.isEmpty())
            out.append(stack.pop());
        result.add(out.toString());
    }
}
